package cn.fl.ref.contract.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cn.fl.framework.base.context.CurrentThreadContext;
import cn.fl.ref.contract.service.IFncPrjContDetailService;
import cn.fl.ref.contract.transform.FncPrjContDetailVOTransform;
import cn.fl.ref.contract.vo.FncPrjContDetailVO;
import cn.cmm.base.framework.utils.CollectionUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import fl.ref.contract.api.IFncPrjContDetailApiService;
import fl.ref.contract.condition.FncPrjContDetailQueryCondition;
import fl.ref.contract.dto.FncPrjContDetailDTO;

/**
 * @Description: 合同管理明细表 客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class FncPrjContDetailServiceImpl implements IFncPrjContDetailService {

	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(IFncPrjContDetailService.class);
	
	/**
	 * TODO 自定义 API 暴露服务
	 */
	@Autowired
	private IFncPrjContDetailApiService fncPrjContDetailApiService;

	@Override
	public FncPrjContDetailVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		//TODO 业务逻辑
		FncPrjContDetailDTO dto = this.fncPrjContDetailApiService.selectById(id);
		return FncPrjContDetailVOTransform.toVO(dto);
	}

	@Override
	public Long add(FncPrjContDetailVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return this.fncPrjContDetailApiService.add(FncPrjContDetailVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.fncPrjContDetailApiService.removeById(id);
	}
	
	/**
     * 删除
     * @param ids
     * @return
     */
    public boolean removeByIds(List<Long> ids)throws BaseException{
    	if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "removeByIds", "删除主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		};
		return false;
    }

	@Override
	public boolean modify(FncPrjContDetailVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.fncPrjContDetailApiService.modify(FncPrjContDetailVOTransform.toDTO(entity));
	}

	/**
     * 批量修改合同明细
     * @param List<FncPrjContDetailVO>
     * @return
     */
	@Override
	public boolean batchModifyDetailInfo(List<FncPrjContDetailVO> vos) throws BaseException {
		if(null == vos){
			BaseLogUtils.info(logger, "batchModifyDetailInfo", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return this.fncPrjContDetailApiService.batchModifyDetailInfo(FncPrjContDetailVOTransform.toDTOList(vos));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		return this.fncPrjContDetailApiService.searchListPage(page);
	}
	
	/**
     * 不分页查询所有
     * @param condition
     * @return
     */
	@Override
	public List<FncPrjContDetailVO> searchList(FncPrjContDetailQueryCondition condition) throws BaseException {
		if(null == condition){
			condition = new FncPrjContDetailQueryCondition();
		}
		return FncPrjContDetailVOTransform.toVOList(this.fncPrjContDetailApiService.searchList(condition));
	}
	@Override
	public List<FncPrjContDetailVO> searchListByIds(List<Long> ids) throws BaseException {
		if(CollectionUtils.isEmpty(ids)){
    		BaseLogUtils.info(logger, "searchListByIds", "查询主键参数集合不能为空!", CurrentThreadContext.getCurrentUserName());
		};
		return FncPrjContDetailVOTransform.toVOList(this.fncPrjContDetailApiService.searchListByIds(ids));
	}
}
